home *** CD-ROM | disk | FTP | other *** search
Wrap
# Source Generated with Decompyle++ # File: in.pyc (Python 2.6) from DistUpgradeGettext import gettext as _ from DistUpgradeGettext import ngettext import subprocess from subprocess import Popen, PIPE import apt import os import apt_pkg import signal import glob from DistUpgradeAufs import doAufsChroot, doAufsChrootRsync from DistUpgradeApport import * def FuzzyTimeToStr(sec): ''' return the time a bit fuzzy (no seconds if time > 60 secs ''' sec = int(sec) days = sec / 86400 hours = sec / 3600 % 24 minutes = sec / 60 % 60 seconds = sec % 60 if seconds == 0: seconds = 1 map = { 'str_days': '', 'str_hours': '', 'str_minutes': '', 'str_seconds': '' } if days > 0: map['str_days'] = ngettext('%li day', '%li days', days) % days if hours > 0: map['str_hours'] = ngettext('%li hour', '%li hours', hours) % hours if minutes > 0: map['str_minutes'] = ngettext('%li minute', '%li minutes', minutes) % minutes map['str_seconds'] = ngettext('%li second', '%li seconds', seconds) % seconds if days > 0: return _('%(str_days)s %(str_hours)s') % map if hours > 3: return map['str_hours'] if hours > 0: return _('%(str_hours)s %(str_minutes)s') % map if minutes > 0: return map['str_minutes'] return map['str_seconds'] class FetchProgress(apt.progress.FetchProgress): def __init__(self): apt.progress.FetchProgress.__init__(self) self.est_speed = 0 def pulse(self): apt.progress.FetchProgress.pulse(self) if self.currentCPS > self.est_speed: self.est_speed = (self.est_speed + self.currentCPS) / 2 return True def estimatedDownloadTime(self, requiredDownload): ''' get the estimated download time ''' if self.est_speed == 0: timeModem = requiredDownload / 57344 / 8 timeDSL = requiredDownload / 1048576 / 8 s = _('This download will take about %s with a 1Mbit DSL connection and about %s with a 56k modem.') % (FuzzyTimeToStr(timeDSL), FuzzyTimeToStr(timeModem)) return s s = _('This download will take about %s with your connection. ') % FuzzyTimeToStr(requiredDownload / self.est_speed) return s class InstallProgress(apt.progress.InstallProgress): ''' Base class for InstallProgress that supports some fancy stuff like apport integration ''' def __init__(self): apt.progress.InstallProgress.__init__(self) self.master_fd = None def run(self, pm): pid = self.fork() if pid == 0: if 'RELEASE_UPGRADE_USE_AUFS_CHROOT' in os.environ: if not doAufsChroot(os.environ['RELEASE_UPGRADE_AUFS_RWDIR'], os.environ['RELEASE_UPGRADE_USE_AUFS_CHROOT']): print 'ERROR: failed to setup aufs chroot overlay' os._exit(1) signal.signal(signal.SIGPIPE, signal.SIG_IGN) res = pm.DoInstall(self.writefd) os._exit(res) self.child_pid = pid res = self.waitChild() if res == 0 and 'RELEASE_UPGRADE_RSYNC_AUFS_CHROOT' in os.environ: logging.info('doing rsync commit of the update') if not doAufsChrootRsync(os.environ['RELEASE_UPGRADE_USE_AUFS_CHROOT']): logging.error('FATAL ERROR: doAufsChrootRsync() returned FALSE') return False return res def error(self, pkg, errormsg): ''' install error from a package ''' apt.progress.InstallProgress.error(self, pkg, errormsg) logging.error("got an error from dpkg for pkg: '%s': '%s'" % (pkg, errormsg)) if '/' in pkg: pkg = os.path.basename(pkg) if '_' in pkg: pkg = pkg.split('_')[0] apport_pkgfailure(pkg, errormsg) class DumbTerminal(object): def call(self, cmd, hidden = False): ''' expects a command in the subprocess style (as a list) ''' import subprocess subprocess.call(cmd) (STEP_PREPARE, STEP_MODIFY_SOURCES, STEP_FETCH, STEP_INSTALL, STEP_CLEANUP, STEP_REBOOT, STEP_N) = range(1, 8) (_('Preparing to upgrade'), _('Getting new software channels'), _('Getting new packages'), _('Installing the upgrades'), _('Cleaning up')) class DistUpgradeView(object): ''' abstraction for the upgrade view ''' def __init__(self): pass def getOpCacheProgress(self): ''' return a OpProgress() subclass for the given graphic''' return apt.progress.OpProgress() def getFetchProgress(self): ''' return a fetch progress object ''' return FetchProgress() def getInstallProgress(self, cache = None): ''' return a install progress object ''' return InstallProgress() def getTerminal(self): return DumbTerminal() def updateStatus(self, msg): ''' update the current status of the distUpgrade based on the current view ''' pass def abort(self): ''' provide a visual feedback that the upgrade was aborted ''' pass def setStep(self, step): ''' we have 6 steps current for a upgrade: 1. Analyzing the system 2. Updating repository information 3. fetch packages 3. Performing the upgrade 4. Post upgrade stuff 5. Complete ''' pass def hideStep(self, step): ''' hide a certain step from the GUI ''' pass def showStep(self, step): ''' show a certain step from the GUI ''' pass def confirmChanges(self, summary, changes, downloadSize, actions = None, removal_bold = True): ''' display the list of changed packages (apt.Package) and return if the user confirms them ''' self.confirmChangesMessage = '' self.toInstall = [] self.toUpgrade = [] self.toRemove = [] self.toDowngrade = [] for pkg in changes: if pkg.markedInstall: self.toInstall.append(pkg.name) continue if pkg.markedUpgrade: self.toUpgrade.append(pkg.name) continue if pkg.markedDelete: self.toRemove.append(pkg.name) continue if pkg.markedDowngrade: self.toDowngrade.append(pkg.name) continue self.toInstall.sort() self.toUpgrade.sort() self.toRemove.sort() self.toDowngrade.sort() if not len(self.toInstall) + len(self.toUpgrade) + len(self.toRemove) + len(self.toDowngrade) == len(changes): raise AssertionError msg = '\n' pkgs_remove = len(self.toRemove) pkgs_inst = len(self.toInstall) pkgs_upgrade = len(self.toUpgrade) if pkgs_remove > 0: msg += ngettext('%d package is going to be removed.', '%d packages are going to be removed.', pkgs_remove) % pkgs_remove msg += ' ' if pkgs_inst > 0: msg += ngettext('%d new package is going to be installed.', '%d new packages are going to be installed.', pkgs_inst) % pkgs_inst msg += ' ' if pkgs_upgrade > 0: msg += ngettext('%d package is going to be upgraded.', '%d packages are going to be upgraded.', pkgs_upgrade) % pkgs_upgrade msg += ' ' if downloadSize > 0: msg += _('\n\nYou have to download a total of %s. ') % apt_pkg.SizeToStr(downloadSize) msg += self.getFetchProgress().estimatedDownloadTime(downloadSize) if pkgs_upgrade + pkgs_inst + pkgs_remove > 100: msg += '\n\n%s' % _('Fetching and installing the upgrade can take several hours. Once the download has finished, the process cannot be cancelled.') if pkgs_upgrade + pkgs_inst + pkgs_remove < 1: summary = _('Your system is up-to-date') msg = _('There are no upgrades available for your system. The upgrade will now be canceled.') self.error(summary, msg) return False self.confirmChangesMessage = msg return True def askYesNoQuestion(self, summary, msg, default = 'No'): """ ask a Yes/No question and return True on 'Yes' """ pass def confirmRestart(self): ''' generic ask about the restart, can be overridden ''' summary = _('Reboot required') msg = _('The upgrade is finished and a reboot is required. Do you want to do this now?') return self.askYesNoQuestion(summary, msg) def error(self, summary, msg, extended_msg = None): ''' display a error ''' pass def information(self, summary, msg, extended_msg = None): ''' display a information msg''' pass def processEvents(self): ''' process gui events (to keep the gui alive during a long computation ''' pass def showDemotions(self, summary, msg, demotions): ''' show demoted packages to the user, default implementation is to just show a information dialog ''' self.information(summary, msg, '\n'.join(demotions)) if __name__ == '__main__': fp = FetchProgress() fp.pulse()